package Contas

import Biblioteca.Livro 

//abstract
class Usuario {
	static transients = ['pass']
	static hasMany = [authorities: Permissao]
	static belongsTo = Permissao

	//Permissao permissao
	String username
	String userRealName = ''
	String passwd
	String email
	boolean emailShow
	boolean enabled = true
	String description = ''
	int telefoneId
	String telefone = ''
	String pass = ''
	String tipo = ''
	

	static constraints = {
		username(blank: false, unique: true, maxSize:30, minSize:4, validator: {return isLetter(it)})
		userRealName(blank: false , maxSize:50, validator: {return Livro.isLetter (it)})
		passwd(blank: false, minSize:6, validator: {return isLetterDigit(it)})
        email(blank: false , email:true , unique:true)
		tipo(blank: false, validator: {return Livro.isLetter (it)})
		telefone(blank:true , validator: {return (Telefone.isNumb(it) &&  (it.length()) == 10) || it == ''})
		enabled()
	}
	
	public static boolean isLetter (String name){
		def expressaoRegular = /([a-zA-Z]+)/
		return (name ==~ expressaoRegular)
		
	}
	
	public static boolean isLetterDigit (String name){
		def expressaoRegular = /([a-zA-Z0-9]+)/
		return (name ==~ expressaoRegular)
	}
}
